package com.irdstudio.biz.rule.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.biz.rule.service.facade.SRuleParamService;
import com.irdstudio.biz.rule.dao.SRuleParamDao;
import com.irdstudio.biz.rule.dao.domain.SRuleParam;
import com.irdstudio.biz.rule.service.vo.SRuleParamVO;
import com.irdstudio.sdk.beans.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 规则参数信息				<p>
 * @author AutoCoder
 * @date 2019-10-30
 */
@Service("sRuleParamServiceImpl")
public class SRuleParamServiceImpl implements SRuleParamService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(SRuleParamServiceImpl.class);

	@Autowired
	private SRuleParamDao sRuleParamDao;
	
	/**
	 * 新增操作
	 */
	public int insertSRuleParam(SRuleParamVO inSRuleParamVo) {
		logger.debug("当前新增数据为:"+ inSRuleParamVo.toString());
		int num = 0;
		try {
			SRuleParam sRuleParam = new SRuleParam();
			beanCopy(inSRuleParamVo, sRuleParam);
			num = sRuleParamDao.insertSRuleParam(sRuleParam);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(SRuleParamVO inSRuleParamVo) {
		logger.debug("当前删除数据条件为:"+ inSRuleParamVo);
		int num = 0;
		try {
			SRuleParam sRuleParam = new SRuleParam();
			beanCopy(inSRuleParamVo, sRuleParam);
			num = sRuleParamDao.deleteByPk(sRuleParam);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inSRuleParamVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(SRuleParamVO inSRuleParamVo) {
		logger.debug("当前修改数据为:"+ inSRuleParamVo.toString());
		int num = 0;
		try {
			SRuleParam sRuleParam = new SRuleParam();
			beanCopy(inSRuleParamVo, sRuleParam);
			num = sRuleParamDao.updateByPk(sRuleParam);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inSRuleParamVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public SRuleParamVO queryByPk(SRuleParamVO inSRuleParamVo) {
		
		logger.debug("当前查询参数信息为:"+ inSRuleParamVo);
		try {
			SRuleParam querySRuleParam = new SRuleParam();
			beanCopy(inSRuleParamVo, querySRuleParam);
			SRuleParam queryRslSRuleParam = sRuleParamDao.queryByPk(querySRuleParam);
			if (Objects.nonNull(queryRslSRuleParam)) {
				SRuleParamVO outSRuleParamVo = beanCopy(queryRslSRuleParam, new SRuleParamVO());
				logger.debug("当前查询结果为:"+ outSRuleParamVo.toString());
				return outSRuleParamVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<SRuleParamVO> queryAllOwner(SRuleParamVO sRuleParamVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<SRuleParamVO> list = null;
		try {
			List<SRuleParam> sRuleParams = sRuleParamDao.queryAllOwnerByPage(sRuleParamVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ sRuleParams.size());
			pageSet(sRuleParams, sRuleParamVo);
			list = (List<SRuleParamVO>) beansCopy(sRuleParams, SRuleParamVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<SRuleParamVO> queryAllCurrOrg(SRuleParamVO sRuleParamVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<SRuleParam> sRuleParams = sRuleParamDao.queryAllCurrOrgByPage(sRuleParamVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+sRuleParams.size());
		List<SRuleParamVO> list = null;
		try {
			pageSet(sRuleParams, sRuleParamVo);
			list = (List<SRuleParamVO>) beansCopy(sRuleParams, SRuleParamVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<SRuleParamVO> queryAllCurrDownOrg(SRuleParamVO sRuleParamVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<SRuleParam> sRuleParams = sRuleParamDao.queryAllCurrDownOrgByPage(sRuleParamVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ sRuleParams.size());
		List<SRuleParamVO> list = null;
		try {
			pageSet(sRuleParams, sRuleParamVo);
			list = (List<SRuleParamVO>) beansCopy(sRuleParams, SRuleParamVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
}
